package com.demo.apparel.mapper.web;

import com.demo.apparel.dto.CategoryDTO;
import com.demo.apparel.entity.Category;
import com.demo.apparel.vo.web.CategoryWithSubExportVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface WebCategoryMapper {

    @Insert("INSERT INTO categories (id, category, category_name, created_time,updated_time) " +
            "VALUES (#{id}, #{category}, #{categoryName}, NOW(),NOW())")
    int insertCategory(Category category);
    /**
     *
     * @param category
     * @return
     */
    @Select("SELECT COUNT(*) FROM categories WHERE category = #{category}")
    int existsCategory(@Param("category") Integer category);


    @Select("SELECT category, category_name ,id ,created_time,updated_time FROM categories ORDER BY category ASC")
    List<CategoryDTO> getAllCategories();

    /**
     *
     * @return
     */
    @Select("SELECT id, category, category_name AS categoryName FROM categories ORDER BY category ASC")
    List<Category> selectAllCategories();


    @Select("SELECT id ,category, category_name FROM categories")
    List<Map<String, Object>> getAllCategorieses();


    @Select("SELECT category_name FROM categories WHERE category = #{category}")
    String getCategoryNameByCategory(@Param("category") Integer category);

    /**
     * 根据大类ID查询对应的category标识
     */
    @Select("SELECT category FROM categories WHERE id = #{id}")
    Integer getCategoryById(String id);

    /**
     * 根据大类ID删除大类
     */
    @Delete("DELETE FROM categories WHERE id = #{id}")
    int deleteCategoryById(String id);

    @Update("UPDATE categories SET category_name = #{categoryName} WHERE category = #{category}")
    int updateCategoryName(@Param("category") Integer category, @Param("categoryName") String categoryName);

    @Select("SELECT c.id, c.category, c.category_name, c.created_time AS createdTime, " +
            "ct.type_name AS typeName, ct.keywords " +
            "FROM categories c LEFT JOIN clothes_type ct ON c.category = ct.category")
    List<CategoryWithSubExportVO> exportCategoryWithSub();


}

